// pages/index/tedianList.js
const App = getApp();
const navigationBarHeight = (App.statusBarHeight + 44) + 'px'
var config = require('../../utils/config');
var net = require('../../utils/net.js');
var util = require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    navigationBarTitle: '特典',
    navigationBarHeight,

    list:[],
    selectItem:100,
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    new App.ToastPannel();
    this.shopId = options.shopId;
    var select = JSON.parse(options.select);
    this.setData({
      selectItem:select
    })
    console.log('list选中',this.data.selectItem)
    this.requestDetailData();
  },

  requestDetailData: function () {
    var url = config.service.businessDiscountUrl;
    var params = {
      merchantId: this.shopId,
    }
    net.doRequest(url, params, 'GET', true, net.Token, res => {
      console.log('商家详情', res);
      if (res.code == 0) {
        if(res.data.length > 0){
          for(var i = 0; i<res.data.length; i++){
            var item = res.data[i];
            if (!util.isNull(item.limitedAt)) {

              item.limitedAtStr = util.zhuanHuaTime(item.limitedAt, 'Y年M月D日')

            }
          }
        }
       


        this.setData({
          list: res.data
        })
      } else {
        this.show(res.message);
      }

    })

  },


  selectItem:function(e){
    var item = e.currentTarget.dataset.item;
    if(this.data.selectItem.id == item.id){
      console.log('一样');
      this.setData({
        selectItem:{},
      })
      App.globalData.selectIndex = {};
      return;
    }
    this.setData({
      selectItem:item
    })
    App.globalData.selectIndex = item;
    // wx.navigateBack({
      
    // })
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})